package fz.vrd.library.crash;


import androidx.annotation.NonNull;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;

import fz.vrd.library.log.LogFactory;

/**
 * <b>类名称或说明：app异常处理  <br/>
 * <b>创建人： Administrator <br/>
 * <b>时间： 2021/4/29 18:01<br/>
 * <b>修改备注：{ } <br/>
 */
public class CrashHandler implements Thread.UncaughtExceptionHandler {

    @Override
    public void uncaughtException(@NonNull Thread t, @NonNull Throwable e) {
        dealCrashInfo(e);
    }

    void dealCrashInfo(Throwable ex) {
        Writer writer = new StringWriter();
        PrintWriter printWriter = new PrintWriter(writer);
        ex.printStackTrace(printWriter);
        Throwable exCause = ex.getCause();
        while (exCause != null) {
            exCause.printStackTrace(printWriter);
            exCause = exCause.getCause();
        }
        printWriter.close();

    }
}
